setwd(“//.shortcut-targets-by-id/1DPJy8RgFslz3_PSZLLl7Z21mCvQUvnJZ/Manuscripts/Cod Ecotypes GoM /data”)

#install_github(“jokergoo/ComplexHeatmap”) Didn’t install #didn’t install BiocManager::install(“inveRsion”)

Load packages and data

library(devtools)
## Loading required package: usethis
library(bigstatsr)
library(bigsnpr)
library(ggplot2)
library(OutFLANK)
## Loading required package: qvalue
library(vegan)
## Loading required package: permute
## 
## Attaching package: 'permute'
## The following object is masked from 'package:devtools':
## 
##     check
## Loading required package: lattice
## This is vegan 2.6-6.1
library(pheatmap)

bigSNP <- snp_attach(paste0("",  "acod_merged.MAF05_QC.rds"))

#  drop the individual at the 17th position because it is a duplicate. It was a fish that was right in the middle of being red or olive and it accidentally got left in both groups and got sequenced twice. 

G_full <- bigSNP$genotypes[-17,]
pos_full <- bigSNP$map$physical.pos
samp_full <- bigSNP$fam$sample.ID[-17]
pop_full <- bigSNP$fam$family.ID[-17]
chrom_full <- bigSNP$map$chromosome

unique(chrom_full)
##  [1] "NC_044048.1" "NC_044049.1" "NC_044050.1" "NC_044051.1" "NC_044052.1"
##  [6] "NC_044053.1" "NC_044054.1" "NC_044055.1" "NC_044056.1" "NC_044057.1"
## [11] "NC_044058.1" "NC_044059.1" "NC_044060.1" "NC_044061.1" "NC_044062.1"
## [16] "NC_044063.1" "NC_044064.1" "NC_044065.1" "NC_044066.1" "NC_044067.1"
## [21] "NC_044068.1" "NC_044069.1" "NC_044070.1"
dim(G_full)
## [1]     294 2094293
NCORES <- nb_cores()

head(bigSNP$fam)
##   family.ID sample.ID paternal.ID maternal.ID sex affection
## 1      Pop1     16216           0           0   0        -9
## 2      Pop1     16220           0           0   0        -9
## 3      Pop1     16224           0           0   0        -9
## 4      Pop1     16225           0           0   0        -9
## 5      Pop1     16229           0           0   0        -9
## 6      Pop1     16231           0           0   0        -9
head(samp_full)
## [1] 16216 16220 16224 16225 16229 16231
pop.names <- paste0("Pop", 1:9)
pop.IDs<- c("Mass.Winter", 
            "Mass.Red", 
            "Mass.Unknown", 
            "Cashes.Olive", 
            "Cashes.Red",
            "Ice.SWOff", 
            "Ice.SWNear", 
            "Ice.NEOff", 
            "Ice.NENear")
region <- c(rep("GoM", 5), rep("Iceland", 4))
ecotype <- c(rep("Nearshore",5), "Migratory", "Nearshore", 
             "Migratory", "Nearshore")
pop.colors <- c(adjustcolor("darkgreen",1), #mass winter
                adjustcolor("salmon",1), #mass red
                adjustcolor("goldenrod3",0.5), #mass unknown
                adjustcolor("darkgreen",0.75), #cashes olive
                adjustcolor("salmon",0.75), #cashes red
                adjustcolor("darkviolet",1), # Iceland SW Off
                adjustcolor("cornflowerblue",0.5), #Iceland SW Near
                adjustcolor("darkviolet",0.5), #Iceland NE Off
                adjustcolor("cornflowerblue",1) #Iceland NE Near
                )
write.table(data.frame(pop.names,pop.IDs, pop.colors, region, ecotype), "outputs/1-Pops.txt", row.names=FALSE)
samp_full <- data.frame(samp_full)

#Remove sample 17, duplicate
samp_full$Pop <- as.factor(bigSNP$fam$family.ID[-17])


# Add population name to smaple dataframe
samp_full$PopID <- factor(samp_full$Pop, ordered=TRUE)
levels(samp_full$PopID) = pop.IDs # this works because the 
# populations are numbered

head(samp_full)
##   samp_full  Pop       PopID
## 1     16216 Pop1 Mass.Winter
## 2     16220 Pop1 Mass.Winter
## 3     16224 Pop1 Mass.Winter
## 4     16225 Pop1 Mass.Winter
## 5     16229 Pop1 Mass.Winter
## 6     16231 Pop1 Mass.Winter
levels(samp_full$PopID)
## [1] "Mass.Winter"  "Mass.Red"     "Mass.Unknown" "Cashes.Olive" "Cashes.Red"  
## [6] "Ice.SWOff"    "Ice.SWNear"   "Ice.NEOff"    "Ice.NENear"
samp_full$Region <- "GoM"
samp_full$Region[samp_full$Pop %in% c("Pop6", "Pop7",
  "Pop8", "Pop9")] = "Iceland"
samp_full$Ecotype <- "1-Nearshore"
samp_full$Ecotype[samp_full$Pop %in% c("Pop6", "Pop8")] <- "2-Migratory"

samp_full$Region <- as.factor(samp_full$Region)
samp_full$Ecotype <- as.factor(samp_full$Ecotype)
head(samp_full)
##   samp_full  Pop       PopID Region     Ecotype
## 1     16216 Pop1 Mass.Winter    GoM 1-Nearshore
## 2     16220 Pop1 Mass.Winter    GoM 1-Nearshore
## 3     16224 Pop1 Mass.Winter    GoM 1-Nearshore
## 4     16225 Pop1 Mass.Winter    GoM 1-Nearshore
## 5     16229 Pop1 Mass.Winter    GoM 1-Nearshore
## 6     16231 Pop1 Mass.Winter    GoM 1-Nearshore
tail(samp_full)
##     samp_full  Pop      PopID  Region     Ecotype
## 289     18096 Pop9 Ice.NENear Iceland 1-Nearshore
## 290     18097 Pop9 Ice.NENear Iceland 1-Nearshore
## 291     18098 Pop9 Ice.NENear Iceland 1-Nearshore
## 292     18099 Pop9 Ice.NENear Iceland 1-Nearshore
## 293     18100 Pop9 Ice.NENear Iceland 1-Nearshore
## 294     18101 Pop9 Ice.NENear Iceland 1-Nearshore
samp_full$label <- paste(samp_full$Region,samp_full$Ecotype, samp_full$PopID, samp_full$samp_full, sep="_")


### colors for Region and Ecotype ####
samp_full$Region_color <- as.factor(samp_full$Region)
levels(samp_full$Region_color) <- c("blue4", "darkgoldenrod")
samp_full$Region_color <- as.character(samp_full$Region_color) # convert factor back to character 

samp_full$Ecotype_color <- as.factor(samp_full$Ecotype)
levels(samp_full$Ecotype_color) <- c("darkcyan", "seagreen2") 
samp_full$Ecotype_color <- as.character(samp_full$Ecotype_color) # convert factor back to character 

### colors for populations ####
samp_full$PopID_color <- as.factor(samp_full$Pop)
levels(samp_full$PopID_color) <- pop.colors # this works because the populations are ordered by number

samp_full$PopID_color <- as.character(samp_full$PopID_color )
muts <- data.frame(chrom_full, pos_full, Glabel = paste(chrom_full,pos_full, sep="__"))

colnames(G_full) <- muts$Glabel

rownames(G_full) <- samp_full$label

Step 1: Subset data to 50,000 random SNPs and perform PCA.

set.seed(29435798)
index <- sort(sample(1:length(pos_full), 50000))

Gsub <- G_full[,index]


# Recode for bigsnpr package tools
Gsub_snp <- add_code256(big_copy(Gsub,type="raw"),code=bigsnpr:::CODE_012) 

# PCA
# make sure this is run on a code 256 type
# snp object, or it will run forever!
set.seed(6345082)
svd7 <- big_randomSVD(Gsub_snp, 
                      snp_scaleBinom(), 
                      ncores = NCORES,
                      k=2)

plot(svd7, type = "scores") +
  aes(color = pop_full) +
  labs(color = "Population")

pdf("figures/1-Gsub-PCA.pdf", width=5, height=5)
  plot(svd7, type = "scores") +
  aes(color = pop_full) +
  labs(color = "Population")
dev.off()
## quartz_off_screen 
##                 2
# Add PC loadings to sample info
#samp_full$Gsub_PC1 <-  svd7$u[,1]
#samp_full$Gsub_PC2 <-  svd7$u[,2]

# Add PC loadings to muts
muts$Gsub_PC1 <- muts$Gsub_PC2 <-NA
muts$Gsub_PC1[index] <- svd7$v[,1]
muts$Gsub_PC2[index] <- svd7$v[,2]

plot(abs(muts$Gsub_PC1), pch=19, col=adjustcolor("blue",0.01))

View PC Loadings

Chrom 1

index <- sort(which(muts$chrom_full=="NC_044048.1"))
Gsub <- G_full[,index]
# Recode for bigsnpr package tools
Gsub_snp <- add_code256(big_copy(Gsub,type="raw"),code=bigsnpr:::CODE_012) 
set.seed(62385534)
svd7 <- big_randomSVD(Gsub_snp, 
                      snp_scaleBinom(), 
                      ncores = NCORES,
                      k=2)

muts$Gsub_LG1_PC1 <- NA
muts$Gsub_LG1_PC1[index] <- svd7$v[,1]

# Chrom 1
plot(muts$pos_full[muts$chrom_full=="NC_044048.1"], 
     abs(muts$Gsub_LG1_PC1[muts$chrom_full=="NC_044048.1"]), 
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG1", ylab="PC1 loading", xlab="position (bp)")

(maxload1 <- quantile(abs(muts$Gsub_LG1_PC1), probs=0.99, na.rm=TRUE))
##         99% 
## 0.006090969
abline(h=maxload1)

#start
LG1start <- min(which(abs(muts$Gsub_LG1_PC1)>maxload1))
LG1end <- max(which(abs(muts$Gsub_LG1_PC1)>maxload1))

muts[LG1start ,]
##        chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1 Gsub_LG1_PC1
## 33090 NC_044048.1 11299038 NC_044048.1__11299038       NA       NA  0.006117522
LG1start_minus1MB <- max(which(muts$pos_full<muts$pos_full[LG1start]-1000000 & muts$chrom_full=="NC_044048.1"))
muts[LG1start_minus1MB,]
##        chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1 Gsub_LG1_PC1
## 29750 NC_044048.1 10298978 NC_044048.1__10298978       NA       NA 0.0002175627
muts[LG1end,]
##         chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 104012 NC_044048.1 28292263 NC_044048.1__28292263       NA       NA
##        Gsub_LG1_PC1
## 104012  0.006091121
LG1end_plus1MB <- max(which(muts$pos_full<muts$pos_full[LG1end]+1000000 & muts$chrom_full=="NC_044048.1"))
muts[LG1end_plus1MB,]
##         chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 106154 NC_044048.1 29268531 NC_044048.1__29268531       NA       NA
##         Gsub_LG1_PC1
## 106154 -0.0005602807
plot(muts$pos_full[LG1start_minus1MB:LG1end_plus1MB], 
     abs(muts$Gsub_LG1_PC1[LG1start_minus1MB:LG1end_plus1MB]), 
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG1", ylab="PC1 loading", xlab="position (bp)")
abline(v=muts$pos_full[LG1start], col="orange", lwd=2)
abline(v=muts$pos_full[LG1end], col="orange", lwd=2)
abline(h=maxload1, col="lightgrey")

Chrom 2

index <- sort(which(muts$chrom_full=="NC_044049.1"))
Gsub <- G_full[,index]
# Recode for bigsnpr package tools
Gsub_snp <- add_code256(big_copy(Gsub,type="raw"),code=bigsnpr:::CODE_012) 
set.seed(235540968)
svd7 <- big_randomSVD(Gsub_snp, 
                      snp_scaleBinom(), 
                      ncores = NCORES,
                      k=2)

muts$Gsub_LG2_PC1 <- NA
muts$Gsub_LG2_PC1[index] <- svd7$v[,1]

# Chrom 2
plot(muts$pos_full[muts$chrom_full=="NC_044049.1"], 
     abs(muts$Gsub_LG2_PC1[muts$chrom_full=="NC_044049.1"]), 
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG2", ylab="PC1 loading", xlab="position (bp)")

(maxload1 <- quantile(abs(muts$Gsub_LG2_PC1), probs=0.99, na.rm=TRUE))
##        99% 
## 0.01020831
abline(h=maxload1)

#start
LG2start <- min(which(abs(muts$Gsub_LG2_PC1)>maxload1))
LG2end <- max(which(abs(muts$Gsub_LG2_PC1)>maxload1))

muts[LG2start ,]
##         chrom_full pos_full              Glabel Gsub_PC2 Gsub_PC1 Gsub_LG1_PC1
## 111433 NC_044049.1   481246 NC_044049.1__481246       NA       NA           NA
##        Gsub_LG2_PC1
## 111433   0.01027682
LG2start_minus1MB <-min(which(muts$chrom_full=="NC_044049.1"))
# in this case it's just the start of the chromosome
muts[LG2start_minus1MB,]
##         chrom_full pos_full           Glabel Gsub_PC2 Gsub_PC1 Gsub_LG1_PC1
## 109720 NC_044049.1      884 NC_044049.1__884       NA       NA           NA
##         Gsub_LG2_PC1
## 109720 -0.0006092057
muts[LG2end,]
##         chrom_full pos_full               Glabel Gsub_PC2 Gsub_PC1 Gsub_LG1_PC1
## 132871 NC_044049.1  4466546 NC_044049.1__4466546       NA       NA           NA
##        Gsub_LG2_PC1
## 132871   0.01029919
LG2end_plus1MB <- max(which(muts$pos_full<muts$pos_full[LG2end]+1000000 & muts$chrom_full=="NC_044049.1"))
muts[LG2end_plus1MB,]
##         chrom_full pos_full               Glabel Gsub_PC2 Gsub_PC1 Gsub_LG1_PC1
## 135332 NC_044049.1  5434591 NC_044049.1__5434591       NA       NA           NA
##        Gsub_LG2_PC1
## 135332 0.0002754641
plot(muts$pos_full[LG2start_minus1MB:LG2end_plus1MB], 
     abs(muts$Gsub_LG2_PC1[LG2start_minus1MB:LG2end_plus1MB]), 
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG2", ylab="PC1 loading", xlab="position (bp)")
abline(v=muts$pos_full[LG2start], col="orange", lwd=2)
abline(v=muts$pos_full[LG2end], col="orange", lwd=2)
abline(h=maxload1, col="lightgrey")

Chrom 7

index <- sort(which(muts$chrom_full=="NC_044054.1"))
Gsub <- G_full[,index]
# Recode for bigsnpr package tools
Gsub_snp <- add_code256(big_copy(Gsub,type="raw"),code=bigsnpr:::CODE_012) 
set.seed(42348064)
svd7 <- big_randomSVD(Gsub_snp, 
                      snp_scaleBinom(), 
                      ncores = NCORES,
                      k=2)

muts$Gsub_LG7_PC1 <- NA
muts$Gsub_LG7_PC1[index] <- svd7$v[,1]

# Chrom 7
plot(muts$pos_full[muts$chrom_full=="NC_044054.1"], 
     abs(muts$Gsub_LG7_PC1[muts$chrom_full=="NC_044054.1"]), 
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG7", ylab="PC1 loading", xlab="position (bp)")

(maxload1 <- quantile(abs(muts$Gsub_LG7_PC1), probs=0.99, na.rm=TRUE))
##         99% 
## 0.006244065
abline(h=maxload1)

#start
LG7start <- min(which(abs(muts$Gsub_LG7_PC1)>maxload1))
LG7end <- max(which(abs(muts$Gsub_LG7_PC1)>maxload1))

muts[LG7start ,]
##         chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 648745 NC_044054.1 16828712 NC_044054.1__16828712       NA       NA
##        Gsub_LG1_PC1 Gsub_LG2_PC1 Gsub_LG7_PC1
## 648745           NA           NA -0.006261396
LG7start_minus1MB <-max(which(muts$pos_full<muts$pos_full[LG7start]-1000000 & muts$chrom_full=="NC_044054.1"))
# in this case it's just the start of the chromosome
muts[LG7start_minus1MB,]
##         chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 645345 NC_044054.1 15828590 NC_044054.1__15828590       NA       NA
##        Gsub_LG1_PC1 Gsub_LG2_PC1 Gsub_LG7_PC1
## 645345           NA           NA 0.0002948823
muts[LG7end,]
##         chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 696592 NC_044054.1 26336501 NC_044054.1__26336501       NA       NA
##        Gsub_LG1_PC1 Gsub_LG2_PC1 Gsub_LG7_PC1
## 696592           NA           NA -0.006245197
LG7end_plus1MB <- max(which(muts$pos_full<muts$pos_full[LG7end]+1000000 & muts$chrom_full=="NC_044054.1"))
muts[LG7end_plus1MB,]
##         chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 700639 NC_044054.1 27336483 NC_044054.1__27336483       NA       NA
##        Gsub_LG1_PC1 Gsub_LG2_PC1 Gsub_LG7_PC1
## 700639           NA           NA -0.000523632
plot(muts$pos_full[LG7start_minus1MB:LG7end_plus1MB], 
     abs(muts$Gsub_LG7_PC1[LG7start_minus1MB:LG7end_plus1MB]), 
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG7", ylab="PC1 loading", xlab="position (bp)")
abline(v=muts$pos_full[LG7start], col="orange", lwd=2)
abline(v=muts$pos_full[LG7end], col="orange", lwd=2)
abline(h=maxload1, col="lightgrey")

Chrom 12

index <- sort(which(muts$chrom_full=="NC_044059.1"))
Gsub <- G_full[,index]
# Recode for bigsnpr package tools
Gsub_snp <- add_code256(big_copy(Gsub,type="raw"),code=bigsnpr:::CODE_012) 
set.seed(73240982)
svd7 <- big_randomSVD(Gsub_snp, 
                      snp_scaleBinom(), 
                      ncores = NCORES,
                      k=2)

muts$Gsub_LG12_PC1 <- NA
muts$Gsub_LG12_PC1[index] <- svd7$v[,1]

# Chrom 12
plot(muts$pos_full[muts$chrom_full=="NC_044059.1"], 
     abs(muts$Gsub_LG12_PC1[muts$chrom_full=="NC_044059.1"]), 
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG12", ylab="PC1 loading", xlab="position (bp)")


(maxload1 <- quantile(abs(muts$Gsub_LG12_PC1), probs=0.99, na.rm=TRUE))
##         99% 
## 0.008958482
abline(h=maxload1)

#start
LG12start <- min(which(abs(muts$Gsub_LG12_PC1)>maxload1))
LG12end <- max(which(abs(muts$Gsub_LG12_PC1)>maxload1))

muts[LG12start ,]
##          chrom_full pos_full               Glabel Gsub_PC2 Gsub_PC1
## 1098771 NC_044059.1  1809214 NC_044059.1__1809214       NA       NA
##         Gsub_LG1_PC1 Gsub_LG2_PC1 Gsub_LG7_PC1 Gsub_LG12_PC1
## 1098771           NA           NA           NA  -0.008967974
LG12start_minus1MB <-max(which(muts$pos_full<muts$pos_full[LG12start]-1000000 & muts$chrom_full=="NC_044059.1"))
# in this case it's just the start of the chromosome
muts[LG12start_minus1MB,]
##          chrom_full pos_full              Glabel Gsub_PC2 Gsub_PC1 Gsub_LG1_PC1
## 1096496 NC_044059.1   721009 NC_044059.1__721009       NA       NA           NA
##         Gsub_LG2_PC1 Gsub_LG7_PC1 Gsub_LG12_PC1
## 1096496           NA           NA  -0.004226609
muts[LG12end,]
##          chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 1141346 NC_044059.1 13690550 NC_044059.1__13690550       NA       NA
##         Gsub_LG1_PC1 Gsub_LG2_PC1 Gsub_LG7_PC1 Gsub_LG12_PC1
## 1141346           NA           NA           NA  -0.009079696
LG12end_plus1MB <- max(which(muts$pos_full<muts$pos_full[LG12end]+1000000 & muts$chrom_full=="NC_044059.1"))
muts[LG12end_plus1MB,]
##          chrom_full pos_full                Glabel Gsub_PC2 Gsub_PC1
## 1142816 NC_044059.1 14677663 NC_044059.1__14677663       NA       NA
##         Gsub_LG1_PC1 Gsub_LG2_PC1 Gsub_LG7_PC1 Gsub_LG12_PC1
## 1142816           NA           NA           NA  2.969367e-05
plot(muts$pos_full[LG12start_minus1MB:LG12end_plus1MB], 
     abs(muts$Gsub_LG12_PC1[LG12start_minus1MB:LG12end_plus1MB]),
     pch=19, col=adjustcolor("blue",0.1), 
     main="LG12", ylab="PC1 loading", xlab="position (bp)")
abline(v=muts$pos_full[LG12start], col="orange", lwd=2)
abline(v=muts$pos_full[LG12end], col="orange", lwd=2)
abline(h=maxload1, col="lightgrey")

summarize breakpoints

breakpoints <- data.frame(
  LG = c("LG1","LG2", "LG7","LG12"),
  LGstartIndex = c(LG1start,LG2start,LG7start,LG12start),
  LGendIndex = c(LG1end,LG2end,LG7end,LG12end),
  chrom=chrom_full[c(LG1start,LG2start,LG7start,LG12start)],
  LGstartPos = pos_full[c(LG1start,LG2start,LG7start,LG12start)],
  LGendPos = pos_full[c(LG1end,LG2end,LG7end,LG12end)],
  LGstartPos_minus1MB_index = c(LG1start_minus1MB,
                                LG2start_minus1MB,
                                LG7start_minus1MB,
                                LG12start_minus1MB),
  LGendPos_plus1MB_index =c(LG1end_plus1MB,
                                LG2end_plus1MB,
                                LG7end_plus1MB,
                                LG12end_plus1MB)
)

PC just on inversions

Get all LG indexes

LGind <- c(LG1start:LG1end, LG2start:LG2end,
           LG7start:LG7end, LG12start:LG12end)

G_LG <- G_full[,LGind]

head(colnames(G_LG))
## [1] "NC_044048.1__11299038" "NC_044048.1__11299525" "NC_044048.1__11299592"
## [4] "NC_044048.1__11299650" "NC_044048.1__11302157" "NC_044048.1__11302179"
head(rownames(G_LG))
## [1] "GoM_1-Nearshore_Mass.Winter_16216" "GoM_1-Nearshore_Mass.Winter_16220"
## [3] "GoM_1-Nearshore_Mass.Winter_16224" "GoM_1-Nearshore_Mass.Winter_16225"
## [5] "GoM_1-Nearshore_Mass.Winter_16229" "GoM_1-Nearshore_Mass.Winter_16231"
dim(G_LG)
## [1]    294 182786
# Recode for bigsnpr package tools
G_LG_snp <- add_code256(big_copy(G_LG,type="raw"),code=bigsnpr:::CODE_012) 

# PCA
# make sure this is run on a code 256 type
# snp object, or it will run forever!
set.seed(3459723)
svd7 <- big_randomSVD(G_LG_snp, 
                      snp_scaleBinom(), 
                      ncores = NCORES,
                      k=2)


samp_full$G_AllInv_PC1 <- svd7$u[,1]
samp_full$G_AllInv_PC2 <- svd7$u[,2]

pdf("figures/PCA-samples-inversion-SNPs-only.pdf", width=6, height=6)
ggplot(samp_full) + geom_point(aes(x=G_AllInv_PC1,
                                   y=G_AllInv_PC2,
                                    colour = PopID,
                                   shape= Ecotype,
                                   pch=Ecotype)) +
    scale_colour_manual(values=pop.colors) +
      xlab("Sample loadings PC1 - inversion SNPs only") +
    ylab("Sample loadings PC2 - inversion SNPs only") +
  theme_classic()
## Warning: Duplicated aesthetics after name standardisation: shape
## Duplicated aesthetics after name standardisation: shape
dev.off()
## quartz_off_screen 
##                 2
dist <- dist(G_LG, diag=TRUE)

str(dist)
##  'dist' num [1:43071] 297 281 298 287 256 ...
##  - attr(*, "Size")= int 294
##  - attr(*, "Labels")= chr [1:294] "GoM_1-Nearshore_Mass.Winter_16216" "GoM_1-Nearshore_Mass.Winter_16220" "GoM_1-Nearshore_Mass.Winter_16224" "GoM_1-Nearshore_Mass.Winter_16225" ...
##  - attr(*, "Diag")= logi TRUE
##  - attr(*, "Upper")= logi FALSE
##  - attr(*, "method")= chr "euclidean"
##  - attr(*, "call")= language dist(x = G_LG, diag = TRUE)
hc <- hclust(dist)
str(hc)
## List of 7
##  $ merge      : int [1:293, 1:2] -21 -8 -54 -223 -193 -218 -151 -138 7 -166 ...
##  $ height     : num [1:293] 104 110 119 196 198 ...
##  $ order      : int [1:294] 146 258 230 147 172 238 243 142 164 156 ...
##  $ labels     : chr [1:294] "GoM_1-Nearshore_Mass.Winter_16216" "GoM_1-Nearshore_Mass.Winter_16220" "GoM_1-Nearshore_Mass.Winter_16224" "GoM_1-Nearshore_Mass.Winter_16225" ...
##  $ method     : chr "complete"
##  $ call       : language hclust(d = dist)
##  $ dist.method: chr "euclidean"
##  - attr(*, "class")= chr "hclust"
dhc <- as.dendrogram(hc)
cut_avg <- cutree(hc, k = 5)
str(cut_avg)
##  Named int [1:294] 1 1 2 1 1 1 1 1 1 1 ...
##  - attr(*, "names")= chr [1:294] "GoM_1-Nearshore_Mass.Winter_16216" "GoM_1-Nearshore_Mass.Winter_16220" "GoM_1-Nearshore_Mass.Winter_16224" "GoM_1-Nearshore_Mass.Winter_16225" ...
str(dhc)
## --[dendrogram w/ 2 branches and 294 members at h = 554]
##   |--[dendrogram w/ 2 branches and 97 members at h = 375]
##   |  |--[dendrogram w/ 2 branches and 54 members at h = 275]
##   |  |  |--[dendrogram w/ 2 branches and 6 members at h = 219]
##   |  |  |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18014" 
##   |  |  |  `--[dendrogram w/ 2 branches and 5 members at h = 215]
##   |  |  |     |--leaf "Iceland_1-Nearshore_Ice.NENear_18058" 
##   |  |  |     `--[dendrogram w/ 2 branches and 4 members at h = 211]
##   |  |  |        |--leaf "Iceland_2-Migratory_Ice.NEOff_18122" 
##   |  |  |        `--[dendrogram w/ 2 branches and 3 members at h = 209]
##   |  |  |           |--leaf "Iceland_2-Migratory_Ice.SWOff_18015" 
##   |  |  |           `--[dendrogram w/ 2 branches and 2 members at h = 206]
##   |  |  |              |--leaf "Iceland_2-Migratory_Ice.SWOff_18047" 
##   |  |  |              `--leaf "Iceland_2-Migratory_Ice.NEOff_18131" 
##   |  |  `--[dendrogram w/ 2 branches and 48 members at h = 234]
##   |  |     |--[dendrogram w/ 2 branches and 10 members at h = 214]
##   |  |     |  |--leaf "Iceland_2-Migratory_Ice.NEOff_18138" 
##   |  |     |  `--[dendrogram w/ 2 branches and 9 members at h = 213]
##   |  |     |     |--[dendrogram w/ 2 branches and 4 members at h = 210]
##   |  |     |     |  |--[dendrogram w/ 2 branches and 2 members at h = 208]
##   |  |     |     |  |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18008" 
##   |  |     |     |  |  `--leaf "Iceland_2-Migratory_Ice.SWOff_18038" 
##   |  |     |     |  `--[dendrogram w/ 2 branches and 2 members at h = 208]
##   |  |     |     |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18029" 
##   |  |     |     |     `--leaf "Iceland_2-Migratory_Ice.NEOff_18118" 
##   |  |     |     `--[dendrogram w/ 2 branches and 5 members at h = 211]
##   |  |     |        |--leaf "Iceland_2-Migratory_Ice.SWOff_18010" 
##   |  |     |        `--[dendrogram w/ 2 branches and 4 members at h = 209]
##   |  |     |           |--leaf "Iceland_2-Migratory_Ice.SWOff_18044" 
##   |  |     |           `--[dendrogram w/ 2 branches and 3 members at h = 207]
##   |  |     |              |--leaf "Iceland_2-Migratory_Ice.SWOff_18030" 
##   |  |     |              `--[dendrogram w/ 2 branches and 2 members at h = 204]
##   |  |     |                 |--leaf "Iceland_2-Migratory_Ice.NEOff_18109" 
##   |  |     |                 `--leaf "Iceland_2-Migratory_Ice.NEOff_18124" 
##   |  |     `--[dendrogram w/ 2 branches and 38 members at h = 219]
##   |  |        |--leaf "Iceland_2-Migratory_Ice.NEOff_18140" 
##   |  |        `--[dendrogram w/ 2 branches and 37 members at h = 217]
##   |  |           |--leaf "Iceland_2-Migratory_Ice.NEOff_18147" 
##   |  |           `--[dendrogram w/ 2 branches and 36 members at h = 213]
##   |  |              |--leaf "Iceland_2-Migratory_Ice.NEOff_18146" 
##   |  |              `--[dendrogram w/ 2 branches and 35 members at h = 212]
##   |  |                 |--[dendrogram w/ 2 branches and 32 members at h = 211]
##   |  |                 |  |--[dendrogram w/ 2 branches and 30 members at h = 209]
##   |  |                 |  |  |--[dendrogram w/ 2 branches and 2 members at h = 207]
##   |  |                 |  |  |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18001" 
##   |  |                 |  |  |  `--leaf "Iceland_2-Migratory_Ice.SWOff_18049" 
##   |  |                 |  |  `--[dendrogram w/ 2 branches and 28 members at h = 209]
##   |  |                 |  |     |--[dendrogram w/ 2 branches and 19 members at h = 207]
##   |  |                 |  |     |  |--[dendrogram w/ 2 branches and 12 members at h = 206]
##   |  |                 |  |     |  |  |--[dendrogram w/ 2 branches and 8 members at h = 203]
##   |  |                 |  |     |  |  |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18003" 
##   |  |                 |  |     |  |  |  `--[dendrogram w/ 2 branches and 7 members at h = 202]
##   |  |                 |  |     |  |  |     |--leaf "Iceland_2-Migratory_Ice.NEOff_18141" 
##   |  |                 |  |     |  |  |     `--[dendrogram w/ 2 branches and 6 members at h = 201]
##   |  |                 |  |     |  |  |        |--[dendrogram w/ 2 branches and 4 members at h = 199]
##   |  |                 |  |     |  |  |        |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18021" 
##   |  |                 |  |     |  |  |        |  `--[dendrogram w/ 2 branches and 3 members at h = 198]
##   |  |                 |  |     |  |  |        |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18170" 
##   |  |                 |  |     |  |  |        |     `--[dendrogram w/ 2 branches and 2 members at h = 196]
##   |  |                 |  |     |  |  |        |        |--leaf "Iceland_2-Migratory_Ice.NEOff_18113" 
##   |  |                 |  |     |  |  |        |        `--leaf "Iceland_2-Migratory_Ice.NEOff_18128" 
##   |  |                 |  |     |  |  |        `--[dendrogram w/ 2 branches and 2 members at h = 200]
##   |  |                 |  |     |  |  |           |--leaf "Iceland_2-Migratory_Ice.SWOff_18002" 
##   |  |                 |  |     |  |  |           `--leaf "Iceland_2-Migratory_Ice.SWOff_18046" 
##   |  |                 |  |     |  |  `--[dendrogram w/ 2 branches and 4 members at h = 204]
##   |  |                 |  |     |  |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18013" 
##   |  |                 |  |     |  |     `--[dendrogram w/ 2 branches and 3 members at h = 203]
##   |  |                 |  |     |  |        |--leaf "Iceland_2-Migratory_Ice.SWOff_18031" 
##   |  |                 |  |     |  |        `--[dendrogram w/ 2 branches and 2 members at h = 199]
##   |  |                 |  |     |  |           |--leaf "Iceland_2-Migratory_Ice.NEOff_18106" 
##   |  |                 |  |     |  |           `--leaf "Iceland_2-Migratory_Ice.NEOff_18133" 
##   |  |                 |  |     |  `--[dendrogram w/ 2 branches and 7 members at h = 206]
##   |  |                 |  |     |     |--[dendrogram w/ 2 branches and 5 members at h = 204]
##   |  |                 |  |     |     |  |--[dendrogram w/ 2 branches and 2 members at h = 202]
##   |  |                 |  |     |     |  |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18026" 
##   |  |                 |  |     |     |  |  `--leaf "Iceland_2-Migratory_Ice.NEOff_18130" 
##   |  |                 |  |     |     |  `--[dendrogram w/ 2 branches and 3 members at h = 203]
##   |  |                 |  |     |     |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18025" 
##   |  |                 |  |     |     |     `--[dendrogram w/ 2 branches and 2 members at h = 201]
##   |  |                 |  |     |     |        |--leaf "Iceland_2-Migratory_Ice.SWOff_18040" 
##   |  |                 |  |     |     |        `--leaf "Iceland_2-Migratory_Ice.NEOff_18125" 
##   |  |                 |  |     |     `--[dendrogram w/ 2 branches and 2 members at h = 205]
##   |  |                 |  |     |        |--leaf "Iceland_2-Migratory_Ice.SWOff_18034" 
##   |  |                 |  |     |        `--leaf "Iceland_2-Migratory_Ice.NEOff_18149" 
##   |  |                 |  |     `--[dendrogram w/ 2 branches and 9 members at h = 208]
##   |  |                 |  |        |--[dendrogram w/ 2 branches and 3 members at h = 206]
##   |  |                 |  |        |  |--leaf "Iceland_2-Migratory_Ice.NEOff_18103" 
##   |  |                 |  |        |  `--[dendrogram w/ 2 branches and 2 members at h = 203]
##   |  |                 |  |        |     |--leaf "Iceland_2-Migratory_Ice.NEOff_18104" 
##   |  |                 |  |        |     `--leaf "Iceland_2-Migratory_Ice.NEOff_18112" 
##   |  |                 |  |        `--[dendrogram w/ 2 branches and 6 members at h = 206]
##   |  |                 |  |           |--[dendrogram w/ 2 branches and 3 members at h = 205]
##   |  |                 |  |           |  |--leaf "Iceland_2-Migratory_Ice.NEOff_18126" 
##   |  |                 |  |           |  `--[dendrogram w/ 2 branches and 2 members at h = 203]
##   |  |                 |  |           |     |--leaf "Iceland_2-Migratory_Ice.NEOff_18108" 
##   |  |                 |  |           |     `--leaf "Iceland_2-Migratory_Ice.NEOff_18151" 
##   |  |                 |  |           `--[dendrogram w/ 2 branches and 3 members at h = 206]
##   |  |                 |  |              |--leaf "Iceland_2-Migratory_Ice.NEOff_18143" 
##   |  |                 |  |              `--[dendrogram w/ 2 branches and 2 members at h = 204]
##   |  |                 |  |                 |--leaf "Iceland_2-Migratory_Ice.SWOff_18033" 
##   |  |                 |  |                 `--leaf "Iceland_2-Migratory_Ice.SWOff_18039" 
##   |  |                 |  `--[dendrogram w/ 2 branches and 2 members at h = 210]
##   |  |                 |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18012" 
##   |  |                 |     `--leaf "Iceland_2-Migratory_Ice.NEOff_18150" 
##   |  |                 `--[dendrogram w/ 2 branches and 3 members at h = 211]
##   |  |                    |--leaf "Iceland_2-Migratory_Ice.SWOff_18051" 
##   |  |                    `--[dendrogram w/ 2 branches and 2 members at h = 208]
##   |  |                       |--leaf "Iceland_2-Migratory_Ice.NEOff_18123" 
##   |  |                       `--leaf "Iceland_2-Migratory_Ice.NEOff_18139" 
##   |  `--[dendrogram w/ 2 branches and 43 members at h = 344]
##   |     |--[dendrogram w/ 2 branches and 28 members at h = 299]
##   |     |  |--[dendrogram w/ 2 branches and 4 members at h = 249]
##   |     |  |  |--leaf "Iceland_1-Nearshore_Ice.SWNear_18152" 
##   |     |  |  `--[dendrogram w/ 2 branches and 3 members at h = 243]
##   |     |  |     |--leaf "Iceland_2-Migratory_Ice.NEOff_18119" 
##   |     |  |     `--[dendrogram w/ 2 branches and 2 members at h = 229]
##   |     |  |        |--leaf "Iceland_2-Migratory_Ice.NEOff_18117" 
##   |     |  |        `--leaf "Iceland_2-Migratory_Ice.NEOff_18148" 
##   |     |  `--[dendrogram w/ 2 branches and 24 members at h = 269]
##   |     |     |--[dendrogram w/ 2 branches and 21 members at h = 236]
##   |     |     |  |--leaf "Iceland_2-Migratory_Ice.NEOff_18127" 
##   |     |     |  `--[dendrogram w/ 2 branches and 20 members at h = 232]
##   |     |     |     |--leaf "Iceland_2-Migratory_Ice.NEOff_18142" 
##   |     |     |     `--[dendrogram w/ 2 branches and 19 members at h = 229]
##   |     |     |        |--[dendrogram w/ 2 branches and 17 members at h = 226]
##   |     |     |        |  |--[dendrogram w/ 2 branches and 3 members at h = 225]
##   |     |     |        |  |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18075" 
##   |     |     |        |  |  `--[dendrogram w/ 2 branches and 2 members at h = 223]
##   |     |     |        |  |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18017" 
##   |     |     |        |  |     `--leaf "Iceland_2-Migratory_Ice.SWOff_18032" 
##   |     |     |        |  `--[dendrogram w/ 2 branches and 14 members at h = 225]
##   |     |     |        |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18037" 
##   |     |     |        |     `--[dendrogram w/ 2 branches and 13 members at h = 224]
##   |     |     |        |        |--leaf "Iceland_2-Migratory_Ice.SWOff_18019" 
##   |     |     |        |        `--[dendrogram w/ 2 branches and 12 members at h = 221]
##   |     |     |        |           |--[dendrogram w/ 2 branches and 7 members at h = 220]
##   |     |     |        |           |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18048" 
##   |     |     |        |           |  `--[dendrogram w/ 2 branches and 6 members at h = 219]
##   |     |     |        |           |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18024" 
##   |     |     |        |           |     `--[dendrogram w/ 2 branches and 5 members at h = 217]
##   |     |     |        |           |        |--leaf "Iceland_2-Migratory_Ice.NEOff_18132" 
##   |     |     |        |           |        `--[dendrogram w/ 2 branches and 4 members at h = 216]
##   |     |     |        |           |           |--leaf "Iceland_2-Migratory_Ice.SWOff_18006" 
##   |     |     |        |           |           `--[dendrogram w/ 2 branches and 3 members at h = 214]
##   |     |     |        |           |              |--leaf "Iceland_1-Nearshore_Ice.NENear_18093" 
##   |     |     |        |           |              `--[dendrogram w/ 2 branches and 2 members at h = 211]
##   |     |     |        |           |                 |--leaf "Iceland_2-Migratory_Ice.SWOff_18041" 
##   |     |     |        |           |                 `--leaf "Iceland_2-Migratory_Ice.NEOff_18115" 
##   |     |     |        |           `--[dendrogram w/ 2 branches and 5 members at h = 221]
##   |     |     |        |              |--[dendrogram w/ 2 branches and 3 members at h = 217]
##   |     |     |        |              |  |--leaf "Iceland_2-Migratory_Ice.SWOff_18022" 
##   |     |     |        |              |  `--[dendrogram w/ 2 branches and 2 members at h = 215]
##   |     |     |        |              |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18005" 
##   |     |     |        |              |     `--leaf "Iceland_2-Migratory_Ice.SWOff_18043" 
##   |     |     |        |              `--[dendrogram w/ 2 branches and 2 members at h = 218]
##   |     |     |        |                 |--leaf "Iceland_2-Migratory_Ice.SWOff_18020" 
##   |     |     |        |                 `--leaf "Iceland_1-Nearshore_Ice.NENear_18081" 
##   |     |     |        `--[dendrogram w/ 2 branches and 2 members at h = 227]
##   |     |     |           |--leaf "Iceland_2-Migratory_Ice.NEOff_18116" 
##   |     |     |           `--leaf "Iceland_2-Migratory_Ice.NEOff_18120" 
##   |     |     `--[dendrogram w/ 2 branches and 3 members at h = 242]
##   |     |        |--leaf "Iceland_1-Nearshore_Ice.SWNear_18186" 
##   |     |        `--[dendrogram w/ 2 branches and 2 members at h = 228]
##   |     |           |--leaf "Iceland_2-Migratory_Ice.NEOff_18136" 
##   |     |           `--leaf "Iceland_1-Nearshore_Ice.NENear_18083" 
##   |     `--[dendrogram w/ 2 branches and 15 members at h = 313]
##   |        |--[dendrogram w/ 2 branches and 3 members at h = 246]
##   |        |  |--leaf "Iceland_1-Nearshore_Ice.SWNear_18187" 
##   |        |  `--[dendrogram w/ 2 branches and 2 members at h = 226]
##   |        |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18160" 
##   |        |     `--leaf "Iceland_1-Nearshore_Ice.NENear_18078" 
##   |        `--[dendrogram w/ 2 branches and 12 members at h = 247]
##   |           |--[dendrogram w/ 2 branches and 3 members at h = 223]
##   |           |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18052" 
##   |           |  `--[dendrogram w/ 2 branches and 2 members at h = 218]
##   |           |     |--leaf "Iceland_1-Nearshore_Ice.NENear_18059" 
##   |           |     `--leaf "Iceland_1-Nearshore_Ice.NENear_18091" 
##   |           `--[dendrogram w/ 2 branches and 9 members at h = 233]
##   |              |--leaf "Iceland_1-Nearshore_Ice.NENear_18099" 
##   |              `--[dendrogram w/ 2 branches and 8 members at h = 232]
##   |                 |--leaf "Iceland_1-Nearshore_Ice.NENear_18082" 
##   |                 `--[dendrogram w/ 2 branches and 7 members at h = 230]
##   |                    |--[dendrogram w/ 2 branches and 5 members at h = 225]
##   |                    |  |--leaf "Iceland_2-Migratory_Ice.NEOff_18110" 
##   |                    |  `--[dendrogram w/ 2 branches and 4 members at h = 223]
##   |                    |     |--leaf "Iceland_1-Nearshore_Ice.NENear_18100" 
##   |                    |     `--[dendrogram w/ 2 branches and 3 members at h = 220]
##   |                    |        |--leaf "Iceland_1-Nearshore_Ice.NENear_18096" 
##   |                    |        `--[dendrogram w/ 2 branches and 2 members at h = 219]
##   |                    |           |--leaf "Iceland_1-Nearshore_Ice.SWNear_18193" 
##   |                    |           `--leaf "Iceland_1-Nearshore_Ice.NENear_18088" 
##   |                    `--[dendrogram w/ 2 branches and 2 members at h = 227]
##   |                       |--leaf "Iceland_1-Nearshore_Ice.SWNear_18159" 
##   |                       `--leaf "Iceland_1-Nearshore_Ice.SWNear_18162" 
##   `--[dendrogram w/ 2 branches and 197 members at h = 466]
##      |--[dendrogram w/ 2 branches and 21 members at h = 363]
##      |  |--[dendrogram w/ 2 branches and 4 members at h = 307]
##      |  |  |--[dendrogram w/ 2 branches and 2 members at h = 237]
##      |  |  |  |--leaf "GoM_1-Nearshore_Mass.Red_17016" 
##      |  |  |  `--leaf "GoM_1-Nearshore_Cashes.Red_17283" 
##      |  |  `--[dendrogram w/ 2 branches and 2 members at h = 252]
##      |  |     |--leaf "GoM_1-Nearshore_Mass.Winter_17285" 
##      |  |     `--leaf "GoM_1-Nearshore_Mass.Red_17008" 
##      |  `--[dendrogram w/ 2 branches and 17 members at h = 332]
##      |     |--[dendrogram w/ 2 branches and 3 members at h = 262]
##      |     |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18056" 
##      |     |  `--[dendrogram w/ 2 branches and 2 members at h = 240]
##      |     |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18155" 
##      |     |     `--leaf "Iceland_1-Nearshore_Ice.NENear_18061" 
##      |     `--[dendrogram w/ 2 branches and 14 members at h = 306]
##      |        |--[dendrogram w/ 2 branches and 5 members at h = 257]
##      |        |  |--[dendrogram w/ 2 branches and 2 members at h = 229]
##      |        |  |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18070" 
##      |        |  |  `--leaf "Iceland_1-Nearshore_Ice.NENear_18094" 
##      |        |  `--[dendrogram w/ 2 branches and 3 members at h = 234]
##      |        |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18180" 
##      |        |     `--[dendrogram w/ 2 branches and 2 members at h = 229]
##      |        |        |--leaf "Iceland_1-Nearshore_Ice.SWNear_18188" 
##      |        |        `--leaf "Iceland_1-Nearshore_Ice.NENear_18086" 
##      |        `--[dendrogram w/ 2 branches and 9 members at h = 278]
##      |           |--leaf "GoM_1-Nearshore_Mass.Winter_16241" 
##      |           `--[dendrogram w/ 2 branches and 8 members at h = 252]
##      |              |--[dendrogram w/ 2 branches and 5 members at h = 232]
##      |              |  |--[dendrogram w/ 2 branches and 3 members at h = 229]
##      |              |  |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18084" 
##      |              |  |  `--[dendrogram w/ 2 branches and 2 members at h = 228]
##      |              |  |     |--leaf "Iceland_2-Migratory_Ice.SWOff_18042" 
##      |              |  |     `--leaf "Iceland_1-Nearshore_Ice.SWNear_18185" 
##      |              |  `--[dendrogram w/ 2 branches and 2 members at h = 231]
##      |              |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18154" 
##      |              |     `--leaf "Iceland_1-Nearshore_Ice.SWNear_18175" 
##      |              `--[dendrogram w/ 2 branches and 3 members at h = 233]
##      |                 |--leaf "Iceland_1-Nearshore_Ice.SWNear_18179" 
##      |                 `--[dendrogram w/ 2 branches and 2 members at h = 230]
##      |                    |--leaf "Iceland_1-Nearshore_Ice.SWNear_18161" 
##      |                    `--leaf "Iceland_1-Nearshore_Ice.NENear_18090" 
##      `--[dendrogram w/ 2 branches and 176 members at h = 401]
##         |--[dendrogram w/ 2 branches and 99 members at h = 368]
##         |  |--[dendrogram w/ 2 branches and 10 members at h = 299]
##         |  |  |--[dendrogram w/ 2 branches and 4 members at h = 250]
##         |  |  |  |--[dendrogram w/ 2 branches and 2 members at h = 228]
##         |  |  |  |  |--leaf "Iceland_1-Nearshore_Ice.SWNear_18189" 
##         |  |  |  |  `--leaf "Iceland_1-Nearshore_Ice.NENear_18077" 
##         |  |  |  `--[dendrogram w/ 2 branches and 2 members at h = 230]
##         |  |  |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18171" 
##         |  |  |     `--leaf "Iceland_1-Nearshore_Ice.NENear_18065" 
##         |  |  `--[dendrogram w/ 2 branches and 6 members at h = 270]
##         |  |     |--[dendrogram w/ 2 branches and 3 members at h = 234]
##         |  |     |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18062" 
##         |  |     |  `--[dendrogram w/ 2 branches and 2 members at h = 225]
##         |  |     |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18173" 
##         |  |     |     `--leaf "Iceland_1-Nearshore_Ice.SWNear_18190" 
##         |  |     `--[dendrogram w/ 2 branches and 3 members at h = 241]
##         |  |        |--leaf "Iceland_1-Nearshore_Ice.SWNear_18164" 
##         |  |        `--[dendrogram w/ 2 branches and 2 members at h = 219]
##         |  |           |--leaf "Iceland_1-Nearshore_Ice.SWNear_18194" 
##         |  |           `--leaf "Iceland_1-Nearshore_Ice.NENear_18092" 
##         |  `--[dendrogram w/ 2 branches and 89 members at h = 358]
##         |     |--[dendrogram w/ 2 branches and 40 members at h = 302]
##         |     |  |--[dendrogram w/ 2 branches and 22 members at h = 254]
##         |     |  |  |--[dendrogram w/ 2 branches and 8 members at h = 249]
##         |     |  |  |  |--[dendrogram w/ 2 branches and 2 members at h = 246]
##         |     |  |  |  |  |--leaf "GoM_1-Nearshore_Mass.Winter_17311" 
##         |     |  |  |  |  `--leaf "GoM_1-Nearshore_Mass.Red_16211" 
##         |     |  |  |  `--[dendrogram w/ 2 branches and 6 members at h = 247]
##         |     |  |  |     |--[dendrogram w/ 2 branches and 3 members at h = 244]
##         |     |  |  |     |  |--leaf "GoM_1-Nearshore_Mass.Unknown_16227" 
##         |     |  |  |     |  `--[dendrogram w/ 2 branches and 2 members at h = 241]
##         |     |  |  |     |     |--leaf "GoM_1-Nearshore_Mass.Unknown_16248" 
##         |     |  |  |     |     `--leaf "GoM_1-Nearshore_Cashes.Olive_17240" 
##         |     |  |  |     `--[dendrogram w/ 2 branches and 3 members at h = 244]
##         |     |  |  |        |--leaf "GoM_1-Nearshore_Cashes.Red_17273" 
##         |     |  |  |        `--[dendrogram w/ 2 branches and 2 members at h = 239]
##         |     |  |  |           |--leaf "GoM_1-Nearshore_Mass.Winter_17324" 
##         |     |  |  |           `--leaf "GoM_1-Nearshore_Mass.Unknown_17288" 
##         |     |  |  `--[dendrogram w/ 2 branches and 14 members at h = 251]
##         |     |  |     |--leaf "GoM_1-Nearshore_Mass.Winter_16220" 
##         |     |  |     `--[dendrogram w/ 2 branches and 13 members at h = 249]
##         |     |  |        |--leaf "GoM_1-Nearshore_Mass.Red_17028" 
##         |     |  |        `--[dendrogram w/ 2 branches and 12 members at h = 247]
##         |     |  |           |--[dendrogram w/ 2 branches and 3 members at h = 242]
##         |     |  |           |  |--leaf "GoM_1-Nearshore_Mass.Winter_16238" 
##         |     |  |           |  `--[dendrogram w/ 2 branches and 2 members at h = 237]
##         |     |  |           |     |--leaf "GoM_1-Nearshore_Mass.Unknown_16240" 
##         |     |  |           |     `--leaf "GoM_1-Nearshore_Mass.Unknown_17292" 
##         |     |  |           `--[dendrogram w/ 2 branches and 9 members at h = 244]
##         |     |  |              |--[dendrogram w/ 2 branches and 4 members at h = 239]
##         |     |  |              |  |--[dendrogram w/ 2 branches and 2 members at h = 236]
##         |     |  |              |  |  |--leaf "GoM_1-Nearshore_Mass.Red_17010" 
##         |     |  |              |  |  `--leaf "GoM_1-Nearshore_Cashes.Red_17265" 
##         |     |  |              |  `--[dendrogram w/ 2 branches and 2 members at h = 236]
##         |     |  |              |     |--leaf "GoM_1-Nearshore_Cashes.Olive_17210" 
##         |     |  |              |     `--leaf "GoM_1-Nearshore_Cashes.Olive_17226" 
##         |     |  |              `--[dendrogram w/ 2 branches and 5 members at h = 242]
##         |     |  |                 |--leaf "GoM_1-Nearshore_Cashes.Olive_17248" 
##         |     |  |                 `--[dendrogram w/ 2 branches and 4 members at h = 239]
##         |     |  |                    |--[dendrogram w/ 2 branches and 2 members at h = 235]
##         |     |  |                    |  |--leaf "GoM_1-Nearshore_Cashes.Red_17253" 
##         |     |  |                    |  `--leaf "GoM_1-Nearshore_Cashes.Red_17258" 
##         |     |  |                    `--[dendrogram w/ 2 branches and 2 members at h = 237]
##         |     |  |                       |--leaf "GoM_1-Nearshore_Mass.Unknown_17002" 
##         |     |  |                       `--leaf "GoM_1-Nearshore_Cashes.Olive_17245" 
##         |     |  `--[dendrogram w/ 2 branches and 18 members at h = 259]
##         |     |     |--[dendrogram w/ 2 branches and 7 members at h = 243]
##         |     |     |  |--leaf "GoM_1-Nearshore_Cashes.Olive_17206" 
##         |     |     |  `--[dendrogram w/ 2 branches and 6 members at h = 239]
##         |     |     |     |--leaf "GoM_1-Nearshore_Mass.Unknown_17033" 
##         |     |     |     `--[dendrogram w/ 2 branches and 5 members at h = 236]
##         |     |     |        |--[dendrogram w/ 2 branches and 2 members at h = 232]
##         |     |     |        |  |--leaf "GoM_1-Nearshore_Mass.Unknown_17304" 
##         |     |     |        |  `--leaf "GoM_1-Nearshore_Cashes.Red_17270" 
##         |     |     |        `--[dendrogram w/ 2 branches and 3 members at h = 236]
##         |     |     |           |--leaf "GoM_1-Nearshore_Mass.Winter_16231" 
##         |     |     |           `--[dendrogram w/ 2 branches and 2 members at h = 231]
##         |     |     |              |--leaf "GoM_1-Nearshore_Mass.Winter_16234" 
##         |     |     |              `--leaf "GoM_1-Nearshore_Cashes.Red_17276" 
##         |     |     `--[dendrogram w/ 2 branches and 11 members at h = 248]
##         |     |        |--[dendrogram w/ 2 branches and 2 members at h = 207]
##         |     |        |  |--leaf "GoM_1-Nearshore_Mass.Winter_17308" 
##         |     |        |  `--leaf "GoM_1-Nearshore_Mass.Winter_17309" 
##         |     |        `--[dendrogram w/ 2 branches and 9 members at h = 245]
##         |     |           |--[dendrogram w/ 2 branches and 6 members at h = 239]
##         |     |           |  |--[dendrogram w/ 2 branches and 2 members at h = 235]
##         |     |           |  |  |--leaf "GoM_1-Nearshore_Mass.Winter_16216" 
##         |     |           |  |  `--leaf "GoM_1-Nearshore_Cashes.Red_17280" 
##         |     |           |  `--[dendrogram w/ 2 branches and 4 members at h = 238]
##         |     |           |     |--[dendrogram w/ 2 branches and 2 members at h = 235]
##         |     |           |     |  |--leaf "GoM_1-Nearshore_Mass.Red_16219" 
##         |     |           |     |  `--leaf "GoM_1-Nearshore_Cashes.Olive_17211" 
##         |     |           |     `--[dendrogram w/ 2 branches and 2 members at h = 236]
##         |     |           |        |--leaf "GoM_1-Nearshore_Mass.Red_17007" 
##         |     |           |        `--leaf "GoM_1-Nearshore_Cashes.Red_17256" 
##         |     |           `--[dendrogram w/ 2 branches and 3 members at h = 242]
##         |     |              |--leaf "GoM_1-Nearshore_Cashes.Olive_17242" 
##         |     |              `--[dendrogram w/ 2 branches and 2 members at h = 234]
##         |     |                 |--leaf "GoM_1-Nearshore_Mass.Winter_16242" 
##         |     |                 `--leaf "GoM_1-Nearshore_Mass.Winter_17306" 
##         |     `--[dendrogram w/ 2 branches and 49 members at h = 339]
##         |        |--[dendrogram w/ 2 branches and 10 members at h = 294]
##         |        |  |--[dendrogram w/ 2 branches and 5 members at h = 242]
##         |        |  |  |--[dendrogram w/ 2 branches and 3 members at h = 237]
##         |        |  |  |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18064" 
##         |        |  |  |  `--[dendrogram w/ 2 branches and 2 members at h = 232]
##         |        |  |  |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18182" 
##         |        |  |  |     `--leaf "Iceland_1-Nearshore_Ice.NENear_18097" 
##         |        |  |  `--[dendrogram w/ 2 branches and 2 members at h = 241]
##         |        |  |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18183" 
##         |        |  |     `--leaf "Iceland_1-Nearshore_Ice.SWNear_18184" 
##         |        |  `--[dendrogram w/ 2 branches and 5 members at h = 253]
##         |        |     |--[dendrogram w/ 2 branches and 3 members at h = 231]
##         |        |     |  |--leaf "Iceland_1-Nearshore_Ice.SWNear_18165" 
##         |        |     |  `--[dendrogram w/ 2 branches and 2 members at h = 228]
##         |        |     |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18166" 
##         |        |     |     `--leaf "Iceland_1-Nearshore_Ice.SWNear_18174" 
##         |        |     `--[dendrogram w/ 2 branches and 2 members at h = 239]
##         |        |        |--leaf "Iceland_1-Nearshore_Ice.SWNear_18172" 
##         |        |        `--leaf "Iceland_1-Nearshore_Ice.SWNear_18191" 
##         |        `--[dendrogram w/ 2 branches and 39 members at h = 316]
##         |           |--[dendrogram w/ 2 branches and 7 members at h = 272]
##         |           |  |--leaf "GoM_1-Nearshore_Mass.Winter_16229" 
##         |           |  `--[dendrogram w/ 2 branches and 6 members at h = 260]
##         |           |     |--leaf "GoM_1-Nearshore_Mass.Winter_17286" 
##         |           |     `--[dendrogram w/ 2 branches and 5 members at h = 248]
##         |           |        |--leaf "GoM_1-Nearshore_Cashes.Olive_17224" 
##         |           |        `--[dendrogram w/ 2 branches and 4 members at h = 244]
##         |           |           |--leaf "GoM_1-Nearshore_Cashes.Olive_17260" 
##         |           |           `--[dendrogram w/ 2 branches and 3 members at h = 238]
##         |           |              |--leaf "GoM_1-Nearshore_Mass.Red_17155" 
##         |           |              `--[dendrogram w/ 2 branches and 2 members at h = 235]
##         |           |                 |--leaf "GoM_1-Nearshore_Mass.Red_17314" 
##         |           |                 `--leaf "GoM_1-Nearshore_Cashes.Red_17281" 
##         |           `--[dendrogram w/ 2 branches and 32 members at h = 281]
##         |              |--[dendrogram w/ 2 branches and 22 members at h = 257]
##         |              |  |--leaf "GoM_1-Nearshore_Mass.Winter_16232" 
##         |              |  `--[dendrogram w/ 2 branches and 21 members at h = 252]
##         |              |     |--[dendrogram w/ 2 branches and 19 members at h = 250]
##         |              |     |  |--[dendrogram w/ 2 branches and 5 members at h = 247]
##         |              |     |  |  |--[dendrogram w/ 2 branches and 2 members at h = 110]
##         |              |     |  |  |  |--leaf "GoM_1-Nearshore_Mass.Winter_16233" 
##         |              |     |  |  |  `--leaf "GoM_1-Nearshore_Cashes.Olive_17233" 
##         |              |     |  |  `--[dendrogram w/ 2 branches and 3 members at h = 245]
##         |              |     |  |     |--leaf "GoM_1-Nearshore_Cashes.Red_17262" 
##         |              |     |  |     `--[dendrogram w/ 2 branches and 2 members at h = 239]
##         |              |     |  |        |--leaf "GoM_1-Nearshore_Cashes.Olive_17221" 
##         |              |     |  |        `--leaf "GoM_1-Nearshore_Cashes.Red_17252" 
##         |              |     |  `--[dendrogram w/ 2 branches and 14 members at h = 249]
##         |              |     |     |--[dendrogram w/ 2 branches and 4 members at h = 246]
##         |              |     |     |  |--leaf "GoM_1-Nearshore_Mass.Red_17031" 
##         |              |     |     |  `--[dendrogram w/ 2 branches and 3 members at h = 245]
##         |              |     |     |     |--leaf "GoM_1-Nearshore_Cashes.Red_17254" 
##         |              |     |     |     `--[dendrogram w/ 2 branches and 2 members at h = 243]
##         |              |     |     |        |--leaf "GoM_1-Nearshore_Mass.Red_17024" 
##         |              |     |     |        `--leaf "GoM_1-Nearshore_Mass.Unknown_16228" 
##         |              |     |     `--[dendrogram w/ 2 branches and 10 members at h = 247]
##         |              |     |        |--leaf "GoM_1-Nearshore_Mass.Winter_16236" 
##         |              |     |        `--[dendrogram w/ 2 branches and 9 members at h = 245]
##         |              |     |           |--[dendrogram w/ 2 branches and 3 members at h = 242]
##         |              |     |           |  |--leaf "GoM_1-Nearshore_Cashes.Red_17268" 
##         |              |     |           |  `--[dendrogram w/ 2 branches and 2 members at h = 239]
##         |              |     |           |     |--leaf "GoM_1-Nearshore_Mass.Winter_17327" 
##         |              |     |           |     `--leaf "GoM_1-Nearshore_Mass.Red_17316" 
##         |              |     |           `--[dendrogram w/ 2 branches and 6 members at h = 244]
##         |              |     |              |--leaf "GoM_1-Nearshore_Mass.Winter_16225" 
##         |              |     |              `--[dendrogram w/ 2 branches and 5 members at h = 240]
##         |              |     |                 |--[dendrogram w/ 2 branches and 3 members at h = 236]
##         |              |     |                 |  |--leaf "GoM_1-Nearshore_Mass.Red_17027" 
##         |              |     |                 |  `--[dendrogram w/ 2 branches and 2 members at h = 234]
##         |              |     |                 |     |--leaf "GoM_1-Nearshore_Mass.Winter_17294" 
##         |              |     |                 |     `--leaf "GoM_1-Nearshore_Cashes.Red_17272" 
##         |              |     |                 `--[dendrogram w/ 2 branches and 2 members at h = 237]
##         |              |     |                    |--leaf "GoM_1-Nearshore_Mass.Red_17313" 
##         |              |     |                    `--leaf "GoM_1-Nearshore_Cashes.Red_17279" 
##         |              |     `--[dendrogram w/ 2 branches and 2 members at h = 251]
##         |              |        |--leaf "GoM_1-Nearshore_Mass.Red_17026" 
##         |              |        `--leaf "GoM_1-Nearshore_Mass.Red_17153" 
##         |              `--[dendrogram w/ 2 branches and 10 members at h = 263]
##         |                 |--[dendrogram w/ 2 branches and 3 members at h = 247]
##         |                 |  |--leaf "GoM_1-Nearshore_Mass.Winter_16247" 
##         |                 |  `--[dendrogram w/ 2 branches and 2 members at h = 238]
##         |                 |     |--leaf "GoM_1-Nearshore_Cashes.Olive_17230" 
##         |                 |     `--leaf "GoM_1-Nearshore_Cashes.Red_17259" 
##         |                 `--[dendrogram w/ 2 branches and 7 members at h = 248]
##         |                    |--[dendrogram w/ 2 branches and 3 members at h = 244]
##         |                    |  |--leaf "GoM_1-Nearshore_Cashes.Red_17271" 
##         |                    |  `--[dendrogram w/ 2 branches and 2 members at h = 241]
##         |                    |     |--leaf "GoM_1-Nearshore_Mass.Winter_17032" 
##         |                    |     `--leaf "GoM_1-Nearshore_Mass.Red_17019" 
##         |                    `--[dendrogram w/ 2 branches and 4 members at h = 247]
##         |                       |--leaf "GoM_1-Nearshore_Cashes.Red_17257" 
##         |                       `--[dendrogram w/ 2 branches and 3 members at h = 243]
##         |                          |--leaf "GoM_1-Nearshore_Cashes.Olive_17204" 
##         |                          `--[dendrogram w/ 2 branches and 2 members at h = 236]
##         |                             |--leaf "GoM_1-Nearshore_Mass.Winter_16239" 
##         |                             `--leaf "GoM_1-Nearshore_Cashes.Red_17282" 
##         `--[dendrogram w/ 2 branches and 77 members at h = 384]
##            |--[dendrogram w/ 2 branches and 30 members at h = 320]
##            |  |--[dendrogram w/ 2 branches and 12 members at h = 268]
##            |  |  |--[dendrogram w/ 2 branches and 5 members at h = 249]
##            |  |  |  |--leaf "GoM_1-Nearshore_Cashes.Olive_17238" 
##            |  |  |  `--[dendrogram w/ 2 branches and 4 members at h = 245]
##            |  |  |     |--leaf "GoM_1-Nearshore_Mass.Unknown_17287" 
##            |  |  |     `--[dendrogram w/ 2 branches and 3 members at h = 241]
##            |  |  |        |--leaf "GoM_1-Nearshore_Cashes.Olive_17234" 
##            |  |  |        `--[dendrogram w/ 2 branches and 2 members at h = 236]
##            |  |  |           |--leaf "GoM_1-Nearshore_Cashes.Olive_17236" 
##            |  |  |           `--leaf "GoM_1-Nearshore_Cashes.Olive_17249" 
##            |  |  `--[dendrogram w/ 2 branches and 7 members at h = 262]
##            |  |     |--leaf "GoM_1-Nearshore_Cashes.Red_17261" 
##            |  |     `--[dendrogram w/ 2 branches and 6 members at h = 252]
##            |  |        |--leaf "GoM_1-Nearshore_Mass.Red_17011" 
##            |  |        `--[dendrogram w/ 2 branches and 5 members at h = 242]
##            |  |           |--leaf "GoM_1-Nearshore_Cashes.Olive_17219" 
##            |  |           `--[dendrogram w/ 2 branches and 4 members at h = 237]
##            |  |              |--[dendrogram w/ 2 branches and 2 members at h = 232]
##            |  |              |  |--leaf "GoM_1-Nearshore_Mass.Unknown_16245" 
##            |  |              |  `--leaf "GoM_1-Nearshore_Cashes.Olive_17215" 
##            |  |              `--[dendrogram w/ 2 branches and 2 members at h = 235]
##            |  |                 |--leaf "GoM_1-Nearshore_Mass.Winter_17326" 
##            |  |                 `--leaf "GoM_1-Nearshore_Mass.Unknown_17325" 
##            |  `--[dendrogram w/ 2 branches and 18 members at h = 277]
##            |     |--[dendrogram w/ 2 branches and 11 members at h = 257]
##            |     |  |--[dendrogram w/ 2 branches and 3 members at h = 232]
##            |     |  |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18098" 
##            |     |  |  `--[dendrogram w/ 2 branches and 2 members at h = 223]
##            |     |  |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18153" 
##            |     |  |     `--leaf "Iceland_1-Nearshore_Ice.SWNear_18156" 
##            |     |  `--[dendrogram w/ 2 branches and 8 members at h = 243]
##            |     |     |--leaf "Iceland_2-Migratory_Ice.NEOff_18134" 
##            |     |     `--[dendrogram w/ 2 branches and 7 members at h = 238]
##            |     |        |--leaf "Iceland_1-Nearshore_Ice.SWNear_18158" 
##            |     |        `--[dendrogram w/ 2 branches and 6 members at h = 236]
##            |     |           |--[dendrogram w/ 2 branches and 2 members at h = 233]
##            |     |           |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18080" 
##            |     |           |  `--leaf "Iceland_1-Nearshore_Ice.NENear_18095" 
##            |     |           `--[dendrogram w/ 2 branches and 4 members at h = 233]
##            |     |              |--leaf "Iceland_1-Nearshore_Ice.NENear_18067" 
##            |     |              `--[dendrogram w/ 2 branches and 3 members at h = 231]
##            |     |                 |--leaf "Iceland_1-Nearshore_Ice.NENear_18072" 
##            |     |                 `--[dendrogram w/ 2 branches and 2 members at h = 230]
##            |     |                    |--leaf "Iceland_1-Nearshore_Ice.NENear_18053" 
##            |     |                    `--leaf "Iceland_1-Nearshore_Ice.NENear_18101" 
##            |     `--[dendrogram w/ 2 branches and 7 members at h = 261]
##            |        |--[dendrogram w/ 2 branches and 2 members at h = 237]
##            |        |  |--leaf "Iceland_1-Nearshore_Ice.SWNear_18163" 
##            |        |  `--leaf "Iceland_1-Nearshore_Ice.SWNear_18167" 
##            |        `--[dendrogram w/ 2 branches and 5 members at h = 242]
##            |           |--leaf "Iceland_1-Nearshore_Ice.NENear_18085" 
##            |           `--[dendrogram w/ 2 branches and 4 members at h = 234]
##            |              |--leaf "Iceland_1-Nearshore_Ice.SWNear_18178" 
##            |              `--[dendrogram w/ 2 branches and 3 members at h = 234]
##            |                 |--leaf "Iceland_2-Migratory_Ice.SWOff_18035" 
##            |                 `--[dendrogram w/ 2 branches and 2 members at h = 231]
##            |                    |--leaf "Iceland_1-Nearshore_Ice.NENear_18069" 
##            |                    `--leaf "Iceland_1-Nearshore_Ice.NENear_18087" 
##            `--[dendrogram w/ 2 branches and 47 members at h = 356]
##               |--[dendrogram w/ 2 branches and 3 members at h = 287]
##               |  |--leaf "Iceland_1-Nearshore_Ice.NENear_18076" 
##               |  `--[dendrogram w/ 2 branches and 2 members at h = 251]
##               |     |--leaf "GoM_1-Nearshore_Cashes.Olive_17203" 
##               |     `--leaf "GoM_1-Nearshore_Cashes.Olive_17218" 
##               `--[dendrogram w/ 2 branches and 44 members at h = 333]
##                  |--[dendrogram w/ 2 branches and 6 members at h = 262]
##                  |  |--leaf "Iceland_1-Nearshore_Ice.SWNear_18168" 
##                  |  `--[dendrogram w/ 2 branches and 5 members at h = 244]
##                  |     |--leaf "Iceland_1-Nearshore_Ice.SWNear_18176" 
##                  |     `--[dendrogram w/ 2 branches and 4 members at h = 233]
##                  |        |--leaf "Iceland_1-Nearshore_Ice.NENear_18073" 
##                  |        `--[dendrogram w/ 2 branches and 3 members at h = 229]
##                  |           |--leaf "Iceland_1-Nearshore_Ice.NENear_18074" 
##                  |           `--[dendrogram w/ 2 branches and 2 members at h = 224]
##                  |              |--leaf "Iceland_1-Nearshore_Ice.SWNear_18157" 
##                  |              `--leaf "Iceland_1-Nearshore_Ice.SWNear_18192" 
##                  `--[dendrogram w/ 2 branches and 38 members at h = 312]
##                     |--[dendrogram w/ 2 branches and 10 members at h = 259]
##                     |  |--[dendrogram w/ 2 branches and 2 members at h = 240]
##                     |  |  |--leaf "GoM_1-Nearshore_Mass.Red_16218" 
##                     |  |  `--leaf "GoM_1-Nearshore_Cashes.Red_17278" 
##                     |  `--[dendrogram w/ 2 branches and 8 members at h = 248]
##                     |     |--[dendrogram w/ 2 branches and 3 members at h = 243]
##                     |     |  |--leaf "GoM_1-Nearshore_Cashes.Red_17264" 
##                     |     |  `--[dendrogram w/ 2 branches and 2 members at h = 233]
##                     |     |     |--leaf "GoM_1-Nearshore_Mass.Red_17017" 
##                     |     |     `--leaf "GoM_1-Nearshore_Mass.Red_17156" 
##                     |     `--[dendrogram w/ 2 branches and 5 members at h = 245]
##                     |        |--[dendrogram w/ 2 branches and 2 members at h = 240]
##                     |        |  |--leaf "GoM_1-Nearshore_Mass.Red_17006" 
##                     |        |  `--leaf "GoM_1-Nearshore_Mass.Red_17029" 
##                     |        `--[dendrogram w/ 2 branches and 3 members at h = 243]
##                     |           |--leaf "GoM_1-Nearshore_Mass.Winter_17296" 
##                     |           `--[dendrogram w/ 2 branches and 2 members at h = 104]
##                     |              |--leaf "GoM_1-Nearshore_Mass.Winter_17291" 
##                     |              `--leaf "GoM_1-Nearshore_Mass.Unknown_16221" 
##                     `--[dendrogram w/ 2 branches and 28 members at h = 269]
##                        |--[dendrogram w/ 2 branches and 5 members at h = 243]
##                        |  |--leaf "GoM_1-Nearshore_Mass.Red_17003" 
##                        |  `--[dendrogram w/ 2 branches and 4 members at h = 242]
##                        |     |--leaf "GoM_1-Nearshore_Mass.Winter_17298" 
##                        |     `--[dendrogram w/ 2 branches and 3 members at h = 239]
##                        |        |--leaf "GoM_1-Nearshore_Mass.Winter_16249" 
##                        |        `--[dendrogram w/ 2 branches and 2 members at h = 236]
##                        |           |--leaf "GoM_1-Nearshore_Mass.Red_17001" 
##                        |           `--leaf "GoM_1-Nearshore_Cashes.Olive_17277" 
##                        `--[dendrogram w/ 2 branches and 23 members at h = 257]
##                           |--leaf "GoM_1-Nearshore_Cashes.Olive_17216" 
##                           `--[dendrogram w/ 2 branches and 22 members at h = 254]
##                              |--[dendrogram w/ 2 branches and 2 members at h = 119]
##                              |  |--leaf "GoM_1-Nearshore_Mass.Red_17022" 
##                              |  `--leaf "GoM_1-Nearshore_Mass.Red_17023" 
##                              `--[dendrogram w/ 2 branches and 20 members at h = 251]
##                                 |--[dendrogram w/ 2 branches and 8 members at h = 244]
##                                 |  |--[dendrogram w/ 2 branches and 3 members at h = 241]
##                                 |  |  |--leaf "GoM_1-Nearshore_Cashes.Red_17267" 
##                                 |  |  `--[dendrogram w/ 2 branches and 2 members at h = 240]
##                                 |  |     |--leaf "GoM_1-Nearshore_Mass.Winter_17289" 
##                                 |  |     `--leaf "GoM_1-Nearshore_Cashes.Red_17263" 
##                                 |  `--[dendrogram w/ 2 branches and 5 members at h = 244]
##                                 |     |--leaf "GoM_1-Nearshore_Mass.Winter_17303" 
##                                 |     `--[dendrogram w/ 2 branches and 4 members at h = 241]
##                                 |        |--[dendrogram w/ 2 branches and 2 members at h = 234]
##                                 |        |  |--leaf "GoM_1-Nearshore_Mass.Red_17020" 
##                                 |        |  `--leaf "GoM_1-Nearshore_Mass.Unknown_17290" 
##                                 |        `--[dendrogram w/ 2 branches and 2 members at h = 235]
##                                 |           |--leaf "GoM_1-Nearshore_Mass.Red_16214" 
##                                 |           `--leaf "GoM_1-Nearshore_Mass.Red_17013" 
##                                 `--[dendrogram w/ 2 branches and 12 members at h = 249]
##                                    |--leaf "GoM_1-Nearshore_Mass.Red_17018" 
##                                    `--[dendrogram w/ 2 branches and 11 members at h = 246]
##                                       |--leaf "GoM_1-Nearshore_Mass.Unknown_17030" 
##                                       `--[dendrogram w/ 2 branches and 10 members at h = 243]
##                                          |--[dendrogram w/ 2 branches and 4 members at h = 239]
##                                          |  |--leaf "GoM_1-Nearshore_Mass.Unknown_16243" 
##                                          |  `--[dendrogram w/ 2 branches and 3 members at h = 237]
##                                          |     |--leaf "GoM_1-Nearshore_Mass.Red_17154" 
##                                          |     `--[dendrogram w/ 2 branches and 2 members at h = 232]
##                                          |        |--leaf "GoM_1-Nearshore_Mass.Unknown_16223" 
##                                          |        `--leaf "GoM_1-Nearshore_Cashes.Olive_17235" 
##                                          `--[dendrogram w/ 2 branches and 6 members at h = 243]
##                                             |--leaf "GoM_1-Nearshore_Mass.Winter_16224" 
##                                             `--[dendrogram w/ 2 branches and 5 members at h = 240]
##                                                |--leaf "GoM_1-Nearshore_Mass.Red_17015" 
##                                                `--[dendrogram w/ 2 branches and 4 members at h = 238]
##                                                   |--leaf "GoM_1-Nearshore_Mass.Red_17315" 
##                                                   `--[dendrogram w/ 2 branches and 3 members at h = 236]
##                                                      |--leaf "GoM_1-Nearshore_Mass.Red_17005" 
##                                                      `--[dendrogram w/ 2 branches and 2 members at h = 233]
##                                                         |--leaf "GoM_1-Nearshore_Mass.Winter_17305" 
##                                                         `--leaf "GoM_1-Nearshore_Mass.Winter_17317"
# https://www.datacamp.com/tutorial/hierarchical-clustering-R
pdf("figures/Hclust-inversionSNPsonly.pdf", width=15, height=10)
plot(hc, cex=0.3)
rect.hclust(hc , k = 5, border=2:6)
dev.off()
## quartz_off_screen 
##                 2
samp_full$InvHclustOrder <- hc$order
samp_full$InvHclustK5 <- as.numeric(cut_avg)

# this looks like SW near in Iceland is more closely related to GOM then NE NEar in Iceland
table(samp_full$PopID, samp_full$InvHclustK5)
##               
##                 1  2  3  4  5
##   Mass.Winter  22  9  2  1  0
##   Mass.Red     15 17  2  1  0
##   Mass.Unknown  9  5  0  3  0
##   Cashes.Olive 14  5  0  6  0
##   Cashes.Red   19  4  1  1  0
##   Ice.SWOff     0  0  1  1 37
##   Ice.SWNear   14  4  8  6  8
##   Ice.NEOff     0  0  0  1 38
##   Ice.NENear    6  3  7 10 14
pdf("figures/Hclust-inversionSNPsonly-heatmap.pdf", width=15, height=15)
par(oma=c(8,4,4,8))
heatmap(as.matrix(dist), cexRow=0.2, cexCol=0.2, scale="none", ColSideColors=samp_full$PopID_color, RowSideColors=samp_full$PopID_color, )
dev.off()
## quartz_off_screen 
##                 2

save outputs

head(samp_full)
##   samp_full  Pop       PopID Region     Ecotype
## 1     16216 Pop1 Mass.Winter    GoM 1-Nearshore
## 2     16220 Pop1 Mass.Winter    GoM 1-Nearshore
## 3     16224 Pop1 Mass.Winter    GoM 1-Nearshore
## 4     16225 Pop1 Mass.Winter    GoM 1-Nearshore
## 5     16229 Pop1 Mass.Winter    GoM 1-Nearshore
## 6     16231 Pop1 Mass.Winter    GoM 1-Nearshore
##                               label Region_color Ecotype_color PopID_color
## 1 GoM_1-Nearshore_Mass.Winter_16216        blue4      darkcyan   #006400FF
## 2 GoM_1-Nearshore_Mass.Winter_16220        blue4      darkcyan   #006400FF
## 3 GoM_1-Nearshore_Mass.Winter_16224        blue4      darkcyan   #006400FF
## 4 GoM_1-Nearshore_Mass.Winter_16225        blue4      darkcyan   #006400FF
## 5 GoM_1-Nearshore_Mass.Winter_16229        blue4      darkcyan   #006400FF
## 6 GoM_1-Nearshore_Mass.Winter_16231        blue4      darkcyan   #006400FF
##   G_AllInv_PC1 G_AllInv_PC2 InvHclustOrder InvHclustK5
## 1   0.03531921 -0.007908553            146           1
## 2   0.06496404 -0.049032057            258           1
## 3   0.06134477 -0.053768027            230           2
## 4   0.05153129 -0.037532901            147           1
## 5   0.03185495  0.019557487            172           1
## 6   0.04147050  0.003228003            238           1
write.csv(samp_full,"outputs/1-Samples.csv")
saveRDS(samp_full,"outputs/1-Samples.rds")

Save individual inversion files

breakpoints
##     LG LGstartIndex LGendIndex       chrom LGstartPos LGendPos
## 1  LG1        33090     104012 NC_044048.1   11299038 28292263
## 2  LG2       111433     132871 NC_044049.1     481246  4466546
## 3  LG7       648745     696592 NC_044054.1   16828712 26336501
## 4 LG12      1098771    1141346 NC_044059.1    1809214 13690550
##   LGstartPos_minus1MB_index LGendPos_plus1MB_index
## 1                     29750                 106154
## 2                    109720                 135332
## 3                    645345                 700639
## 4                   1096496                1142816
write.csv(breakpoints, "outputs/1-breakpoints.csv", row.names = FALSE)

head(G_full[,1:5]) # make sure rows and columns are labeled
##                                   NC_044048.1__268 NC_044048.1__280
## GoM_1-Nearshore_Mass.Winter_16216                0                2
## GoM_1-Nearshore_Mass.Winter_16220                1                2
## GoM_1-Nearshore_Mass.Winter_16224                1                2
## GoM_1-Nearshore_Mass.Winter_16225                0                0
## GoM_1-Nearshore_Mass.Winter_16229                1                0
## GoM_1-Nearshore_Mass.Winter_16231                1                1
##                                   NC_044048.1__378 NC_044048.1__539
## GoM_1-Nearshore_Mass.Winter_16216                0                1
## GoM_1-Nearshore_Mass.Winter_16220                0                0
## GoM_1-Nearshore_Mass.Winter_16224                0                0
## GoM_1-Nearshore_Mass.Winter_16225                0                0
## GoM_1-Nearshore_Mass.Winter_16229                0                0
## GoM_1-Nearshore_Mass.Winter_16231                0                0
##                                   NC_044048.1__1555
## GoM_1-Nearshore_Mass.Winter_16216                 0
## GoM_1-Nearshore_Mass.Winter_16220                 0
## GoM_1-Nearshore_Mass.Winter_16224                 0
## GoM_1-Nearshore_Mass.Winter_16225                 0
## GoM_1-Nearshore_Mass.Winter_16229                 0
## GoM_1-Nearshore_Mass.Winter_16231                 0
saveRDS(G_LG, "outputs/1-AllLGSNPs.rds")
saveRDS(G_full[,LG1start_minus1MB:LG1end_plus1MB], "outputs/1-G_LG1.rds")
saveRDS(G_full[,LG2start_minus1MB:LG2end_plus1MB], "outputs/1-G_LG2.rds")
saveRDS(G_full[,LG7start_minus1MB:LG7end_plus1MB], "outputs/1-G_LG7.rds")
saveRDS(G_full[,LG12start_minus1MB:LG12end_plus1MB], "outputs/1-G_LG12.rds")